package JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class JDBCDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/birdbootdb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true","root","root");
        Statement state = conn.createStatement();
        Scanner scan = new Scanner(System.in);
        System.out.println("欢迎注册");
        System.out.println("请输入用户名");
        String username = scan.nextLine();
        System.out.println("请输入密码");
        String password = scan.nextLine();
        System.out.println("请输入昵称");
        String nickname = scan.nextLine();
        System.out.println("请输入年龄");
        String age = scan.nextLine();
        String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                     "VALUES ('"+username+"','"+password+"','"+nickname+ "','"+age+"');";
        int num = state.executeUpdate(sql);
        if (num>0){
            System.out.println("修改成功");
        }else {
            System.out.println("修改失败");
        }
        state.close();



    }
}
